<?
header('Content-Type: text/html; charset=utf-8'); 
include "./lib_dbconnection.php";
include "./lib_getdblist.php";
function search_place($pattern){
	$place_ids = getDbList("SELECT place_id FROM places WHERE place_name LIKE '%".$pattern."%';");
	$shop_ids = getDbList("SELECT DISTINCT place_id FROM shops WHERE shop_name LIKE '%".$pattern."%';");
	$suitable_place_ids = $place_ids + $shop_ids;
	if (!empty($suitable_place_ids)){
		$suitable_place_ids = array_unique($suitable_place_ids);
		$query = "SELECT place_id, place_name, place_description, place_address, place_telephone, place_email, place_site FROM places WHERE";
		foreach ($suitable_place_ids as $id){
			$query .= " place_id=$id";
		}
		$query .= ';';
		$query_result = mysql_query($query);
		if( $query_result ) {
    		print("[");
	    	while ( list($place_id, $place_name, $place_description, $place_address, $place_telephone, $place_email, $place_site) = mysql_fetch_row($query_result) ) {
	    		print("{place_id: '$place_id', place_name: '$place_name', place_description: '$place_description', place_address: '$place_address', place_telephone: '$place_telephone', place_email: '$place_email', place_site: '$place_site'},");
	    	}
	    	print("]");
		}
	}else{
		print("[]");
	}
};
?>